package com.hdax.dm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hdax.dm.beans.item.ItemType;
import com.hdax.dm.dto.list.sortgoodsDto;
import com.hdax.dm.mappers.list.listMapper;
import com.hdax.dm.mapstucts.list.sortgoodsDtoMapper;
import com.hdax.dm.service.listService;
import com.hdax.dm.utils.response.CommonResponse;
import com.hdax.dm.utils.response.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import java.util.Set;

@Service
public class listServiceImpl extends ServiceImpl<listMapper, ItemType> implements listService {

    @Autowired
    private sortgoodsDtoMapper sortgoodsDtoMapper;

    @Override
    public CommonResponse<List<sortgoodsDto>> sortgoods(Map<String,Integer> params) {

        Set<String> mapkey = params.keySet();
        String key = "";
        Integer value = 0;
        for (String i:mapkey) {
            key=i;
        }

        if (key.equals("parent")){
            value = params.get("parent");
        }else if(key.equals("param")){
            value = params.get("param");
        }

        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("parent",value);
        List<ItemType> lists = baseMapper.selectList(queryWrapper);
        List<sortgoodsDto> dtos = sortgoodsDtoMapper.toTargetList(lists);
        return ResponseUtil.returnSuccess(dtos);
    }
}
